www.gusucode.com > ROCKOA PHP协同办公OA办公系统 v2.0PHP源码程序 > ROCKOA PHP协同办公OA办公系统 v2.0/rockoa_v2.0/rockoa_v2.0/webrock/model/adminModel.php

    <?php
class adminClassModel extends Model
{
	
	public function gjoin($joinid, $glx='ud', $blx='bxl')
	{
		$uid 	= $did = '0';
		if($this->rock->isempt($joinid))return '';
		if($this->rock->contain($joinid, 'all'))return 'all';
		$narr 	= explode(',', $joinid);
		$dwhe	= array();
		foreach($narr as $sid){
			$lx 	= substr($sid, 0, 1);
			$ssid 	= str_replace(array('u','d','U','D'), array('','','',''), $sid);
			if($lx == 'd' || $glx=='d'){
				$did.=','.$ssid.'';
				$dwhe[] = "instr(`deptpath`, '[$ssid]')>0";
			}else{
				$uid.=','.$ssid.'';
			}
		}
		$where = '';
		if($did != '0'){
			$where = join(' or ', $dwhe);
			if($uid!='0')$where.=" or `id` in($uid)";
		}else{
			if($uid!='0')$where ="`id` in($uid)";
		}
		if($blx == 'where')return $where;
		$guid = '';
		if($where!=''){
			$rows = $this->getall("`status`=1 and `state`<>5 and ($where)", '`id`');
			foreach($rows as $k=>$rs)$guid.=','.$rs['id'].'';
			if($guid !='')$guid = substr($guid, 1);
		}
		return $guid;
	}
	
	/**
		判断某个id是不是在里面
	*/
	public function containjoin($joinid, $myid=0, $glx='ud')
	{
		$bo 	= false;
		$wh 	= $this->gjoin($joinid, $glx, 'where');
		if($wh == 'all')$bo = true;
		if(!$bo && $wh != ''){
			if($this->rows("`id`='$myid' and ($wh)")>0)$bo = true;
		}
		return $bo;
	}
	
	public function getjoinstr($fids, $uid)
	{
		$s 		= '';
		$us 	= $this->getone($uid,'id,`name`,`deptid`,`deptpath`');
		$tj[]	= "ifnull($fids,'')=''";
		$tj[]	= $this->rock->dbinstr($fids, 'all');
		$tj[]	= $this->rock->dbinstr($fids, 'u'.$uid);
		if($us){
			$dep = explode(',', $us['deptpath']);
			foreach($dep as $deps){
				$_deps 	= str_replace(array('[',']'), array('',''), $deps);
				$tj[]	= $this->rock->dbinstr($fids, 'd'.$_deps);
			}
		}
		$s	= join(' or ', $tj);
		if($s != '')$s = ' and ('.$s.')';
		return $s;
	}
	
	/**
		根据模块可获取查看权限
	*/
	public function getextsjoinv($mode, $uid, $gty='uid')
	{
		$tj1	= $this->rock->dbinstr('mode', 'all');
		$tj2	= $this->rock->dbinstr('mode', $mode);
		$s 		= $s1 = $s0 = '';
		$rows 	= $this->db->getall("select `renyid`,`type` from `[Q]sjoinv` where `uid`='$uid' and ($tj1 or $tj2) ");
		foreach($rows as $k=>$rs){
			switch($rs['type']){
				case 1:
					$s1 .=','.$rs['renyid'];
				break;
				case 0:
					$s0 .=','.$rs['renyid'];
				break;
			}
		}
		$whe = $whe1= $whe0 = '';
		if($s1!=''){
			$whe1 = $this->gjoin(substr($s1, 1), 'ud', 'where');
			if($whe1 != '')$whe = ' and '.$whe1.'';
		}
		if($s0!=''){
			$whe0 = $this->gjoin(substr($s0, 1), 'ud', 'where');
			if($whe0 != '')$whe .= ' and not('.$whe0.')';
		}
		if($gty =='where'){
			if($whe=='')$whe='and id=0';
			return $whe;
		}
		$guid = '0';
		if($whe!=''){
			$rows = $this->getall("`status`=1 $whe", '`id`');
			foreach($rows as $k=>$rs)$guid.=','.$rs['id'].'';
		}
		return $guid;
	}

}